Chronometer = function() {
    var start = 0
    var end = 0
    var diff;
    var timerID = 0
    var status = 'stop';
    var that = this;

    // =======================
    var chrono = function() {
        end = new Date();
        diff = end - start;
        diff = new Date(diff);

        timerID = setTimeout(chrono, 10);
    }

    // =======================
    this.chronoStart = function(df) {
        if (status !== 'start') {
            if (df) {
                start = new Date() - df;
                start = new Date(start);
            } else {
                start = new Date();
            }

            chrono();
            status = 'start';
        }
    }

    // =======================
    this.chronoReset = function() {
        diff = undefined;
        start = new Date();
    }

    // =======================
    this.chronoStop = function() {
        if (status !== 'stop') {
            clearTimeout(timerID);
            status = 'stop';
        }

    }
    // =======================
    this.getTimeDiff = function() {
        return diff;
    }
    // =======================
    this.getTimeElapsed = function() {
        if (!diff) {
            return"00:00:00:000";
        }


        var msec = diff.getMilliseconds();
        var sec = diff.getSeconds();
        var min = diff.getMinutes();
        var hr = diff.getHours() - 1;

        if (min < 10) {
            min = "0" + min;
        }

        if (sec < 10) {
            sec = "0" + sec;
        }

        if (msec < 10) {
            msec = "00" + msec;
        } else if (msec < 100) {
            msec = "0" + msec;
        }
        return hr + ":" + min + ":" + sec + ":" + msec;
    }

    this.getStatus = function() {
        return status;
    }
}